const fileInput=document.querySelector('#file')
fileInput.addEventListener('change',()=>{
    const reads = new FileReader();
    const file = document.getElementById("file").files[0];
    reads.readAsDataURL(file);
    reads.onload=function(){
        document.getElementById("showImg").src= this.result;
    }
})
const infoChangeForm=document.querySelector('.infoChangeForm')
const changeUsername=document.querySelector('#name')
const changeAge=document.querySelector('#age')

infoChangeForm.addEventListener('submit',(e)=>{
        e.preventDefault()
        let changeUserNameValue=setText(infoChangeForm.username.value)
        let changeAgeValue=setText(infoChangeForm.age.value)

        let inputValue = document.getElementById('file').value;
    if (inputValue.trim() === "") {
        document.getElementById('file').removeAttribute('name');
    }
    if(changeUserNameValue.length>15){
        showCustomAlert('昵称长度应为1~15个字符',false)
        changeUsername.classList.add('warning')
    }else if (changeAgeValue<0||changeAgeValue>120||!(changeAgeValue%1 === 0)){
        showCustomAlert('年龄必须为0~120间的整数',false)
        changeAge.classList.add('warning')
    }else{
        infoChangeForm.submit()
        // $.ajax({
        //     url:"/weibo/my/toSetUpMyInfo",
        //     type:'post',
        //     data:{
        //
        //     },
        //     success:function (msg){
        //       showCustomAlert("cheggong")
        //       console.log(msg)
        //     },
        //     error:function (msg){
        //       console.log(msg)
        //     }
        //   })

    }


})